package or.exa.cangguan.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import or.exa.cangguan.common.Result;
import or.exa.cangguan.entity.vo.LoadingPositionVo;
import or.exa.cangguan.service.LoadingPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "装卸点管理")
@RestController
public class LoadingPositionController {

    @Autowired
    private LoadingPositionService loadingPositionService;

    //新增装卸点
    @PostMapping("/LoadingPosition/add")
    @ApiOperation(value = "新增装卸点")
    public Result addLoadingPosition(@RequestBody LoadingPositionVo loadingPositionVo) {
        int i = loadingPositionService.addLoadingPosition(loadingPositionVo);
        return i > 0 ? Result.ok("添加成功") : Result.ok("添加失败");
    }

    //删除装卸点
    @PostMapping("/LoadingPosition/delete/{id}")
    @ApiOperation(value = "删除装卸点")
    public Result deleteLoadingPosition(@PathVariable Integer id) {
        int i = loadingPositionService.deleteLoadingPosition(id);
        return i > 0 ? Result.ok("删除成功") : Result.ok("删除失败");
    }

    //更新装卸点
    @PostMapping("/LoadingPosition/update")
    @ApiOperation(value = "修改装卸点")
    public Result updateLoadingPosition(@RequestBody LoadingPositionVo loadingPositionVo) {
        int i = loadingPositionService.updateLoadingPosition(loadingPositionVo);
        return i > 0 ? Result.ok("更新成功") : Result.ok("更新失败");
    }

    //查询装卸点
    @PostMapping("/LoadingPosition/search")
    @ApiOperation(value = "查询装卸点")
    public Result queryLoadingPosition(@RequestBody LoadingPositionVo loadingPositionVo) {
        return Result.ok(loadingPositionService.queryLoadingPosition(loadingPositionVo));
    }


    //查询装卸点名称
    @PostMapping("/LoadingPosition/searchName")
    @ApiOperation(value = "查询装卸点名称")
    public Result queryLoadingPositionName() {
        return Result.ok(loadingPositionService.selectName());
    }


}
